home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS08.ADF / C / IconExec.c < prev    next >
C/C++ Source or Header  |  1986-04-02  |  4KB  |  135 lines

  1.  
  2. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  3. /* ICONEXEC (c) Copyright 1986 John A. Toebes, VIII. All rights reserved */
  4. /*  This program may be used and modified for any purpose so long as     */
  5. /*  this copyright notice remains with the code and the program is not   */
  6. /*  sold and no charge is made for its use.  For permission to           */
  7. /*  incorporate this into a commercial product, contact the author:      */
  8. /*    John A. Toebes, VIII                                               */
  9. /*    120 H Northington Place                                            */
  10. /*    Cary NC 27511                                                      */
  11. /*    (919) 469-4210                                                     */
  12. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  13.  
  14. /*-----------------------------------------------------------------------*/
  15. /* This program allows you to associate any series of CLI commands to be */
  16. /* run when you click on an ICON even though there is no CLI window open */
  17. /* One problem associated with it is that a program that does input from */
  18. /* the default input (*) always sees EOF.  I am researching why this     */
  19. /* happens, but believe it is related to an AmigaDos problem.            */
  20. /*-----------------------------------------------------------------------*/
  21.  
  22. /****************
  23.   To compile this program under Lattice C:
  24.     1) Compile the 
  25.  
  26. LC1 -oRAM: -i<includedir> ICONEXEC
  27.  
  28. LC2 -v -oICONEXEC.O RAM:ICONEXEC
  29.  
  30.     2) Create a file 'link_iconexec' with the linker commands (assuming 
  31.        that df0:lib contains the appropriate linking modules):
  32.  
  33. FROM     :lib/astartup.o+IconExec.o
  34. TO       IconExec
  35. LIBRARY  df0:lib/lc.lib+df0:lib/amiga.lib
  36. MAP      nil:
  37.  
  38.     3) link it using alink
  39.  
  40. ALINK WITH LINK_ICONEXEC
  41.  
  42.  
  43.    To create and execute a user customized Icon Exec
  44.  
  45.     1) Create an Icon (copy the CLI Icon) for IconExec
  46.  
  47.     2) Run the SetWindow program to set a the tool window on the Icon
  48.  
  49. SETWINDOW ICONEXEC "CON:0/0/100/100/MYWINDOW"
  50.        If you do not do this, then by default ICONEXEC will open a full
  51.        screen window with a title of "ICONEXEC by John A. Toebes, VIII"
  52.  
  53.     3) Using the Workbench INFO meno option, enter the commands into the
  54.        tool types window.
  55.  
  56.     4) Click on the Icon and watch it go.
  57. **********/
  58.  
  59. #include <exec/types.h>
  60. #include <workbench/workbench.h>
  61. #include <workbench/icon.h>
  62. #include <workbench/startup.h>
  63. #include <libraries/dos.h>
  64. #include <libraries/dosextens.h>
  65.  
  66. #define DEFAULT_WINDOW "CON:10/10/150/75/ "
  67.  
  68. LONG IconBase;
  69. extern struct WBStartup *WBenchMsg;
  70. extern struct FileHandle *CurrentDir();
  71.  
  72. main()
  73. {
  74. char **tools;
  75. char *thistool;
  76. struct WBArg *wbarg;
  77. struct DiskObject *diskobj, *GetDiskObject();
  78. struct FileHandle *olddir;
  79. char *window;
  80. struct FileHandle *handle;
  81. BPTR file;
  82. struct Process *process;
  83.  
  84. if ( (IconBase = OpenLibrary( ICONNAME, 1) ) == NULL)
  85.    exit(2);
  86.  
  87. /* Locate the first argument passed from workbench */
  88. wbarg= WBenchMsg->sm_ArgList;
  89.  
  90. /* change to its home dir */
  91. olddir= CurrentDir( wbarg->wa_Lock );
  92.  
  93. /* read in its disk object structure */
  94. diskobj= GetDiskObject( wbarg->wa_Name );
  95. if ( !diskobj)
  96.    {
  97.    CloseLibrary( IconBase);
  98.    exit(20);
  99.    }
  100.  
  101. /* did we have a default tool window opened for us ? */
  102. if (WBenchMsg->sm_ToolWindow == NULL)
  103.    {
  104.    /* figure out the window to open */
  105.    if ( (window = diskobj->do_ToolWindow) == NULL)
  106.       window = DEFAULT_WINDOW;
  107.  
  108.    /* open the desired window if we can */
  109.    if ( (file = Open(window,MODE_NEWFILE)) == NULL)
  110.       {
  111.       CloseLibrary( IconBase );
  112.       exit(4);
  113.       }
  114.  
  115.    /* fool system into thinking we have a CLI based window */
  116.    handle = (struct FileHandle *)(file << 2);
  117.    process = (struct Process *)FindTask(0);
  118.    process->pr_ConsoleTask = (APTR)handle->fh_Type;
  119.    process->pr_CurrentDir = wbarg->wa_Lock;
  120.    }
  121. else
  122.    file = Output();
  123.  
  124. /* run through the tools and execute them one at a time */
  125. for (tools = diskobj->do_ToolTypes; thistool=*tools; tools++)
  126.    Execute(thistool, NULL, file);
  127.  
  128. /* close down the window */
  129. if (WBenchMsg->sm_ToolWindow == NULL)
  130.    Close(file);
  131.  
  132. CloseLibrary( IconBase );
  133. }
  134.  
  135.